using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using SanJ.FreeCare.EntityFrameworkCore;
using SanJ.FreeCare.ObservationDefinitions;
using SanJ.FreeCare.ObservationDefinitionItems;

namespace SanJ.FreeCare.Medications
{
    public class EfCoreObservationDefinitionItemRepository : EfCoreObservationDefinitionItemRepositoryBase, IObservationDefinitionItemRepository
    {
        public EfCoreObservationDefinitionItemRepository(IDbContextProvider<FreeCareDbContext> dbContextProvider)
            : base(dbContextProvider)
        {
        }

        public async Task<List<ObservationDefinitionItem>> GetListByObdIdsAsync(List<Guid> obd_Ids, CancellationToken cancellationToken = default)
        {
            var query = await(GetQueryableAsync());
            return await query.Where(x => obd_Ids.Contains(x.ObservationDefinitionId))
                .ToListAsync(cancellationToken);
        }

        public async Task<List<ObservationDefinitionItem>> GetListByObdIdAsync(Guid obd_Id, CancellationToken cancellationToken = default)
        {
            var query = await(GetQueryableAsync());
            return await query.Where(x => obd_Id == x.ObservationDefinitionId)
                .ToListAsync(cancellationToken);
        }
    }
}